#include "main.hpp"

Door::Door() : state(Closed)
{
    charForState[Opened] = '|';
    charForState[Closed] = charForState[Locked] = '+';

    colForState[Opened] = colForState[Closed] = TCODColor(140,70,0);
    colForState[Locked] = TCODColor::red;

}


void Door::applyCurrentState(Actor *owner)
{
    owner->ch = charForState[state];
    owner->col = colForState[state];
    bool opened = (state == Opened);
    owner->blocks = !opened;
    engine.map->map->setProperties(owner->x,owner->y,opened,true);
}

bool Door::trig(int newState, Actor *handler, Actor *owner)
{
    if (state == newState)
        return true;


    if (state != Locked)
    {
        state = static_cast<States>(newState);
        applyCurrentState(owner);
        return true;
    }

    return false;
}
